/**
	Copyright (c) 2009 ATTi 
	All rights reserved.
	Author: Michael Shu
	Date: 12/28/2009
*/

public class SelectTemplateEmailController {
	private List<Folder> lfolder;
	public  Boolean iseTemplateEmpty {get; set;}
	public  Boolean iseTemplateNotEmpty {get; set;}
	public  String selectedFolderId {get; set;}
	public  List<SelectOption> lfolderName{get; set;}
	public  List<EmailTemplate> leTemplate{get; set;}
	
	public SelectTemplateEmailController(){
		lfolderName = new List<SelectOption>();
		ID OrgId = [Select Id from Organization limit 1].Id;
		lfolderName.add(new SelectOption(OrgId, SendEmailControllerMessage.UnfiledPublicFolderName ));
		lfolderName.add(new SelectOption(UserInfo.getUserId(), SendEmailControllerMessage.PersonalFolderName ));
		lFolder = SelectContactController.getFolders();
		if(lFolder != null && !lFolder.isEmpty()){
			for(Folder f : lFolder){
				lfolderName.add(new SelectOption(f.Id, f.Name ));
			}
		}	
		leTemplate= SelectContactController.getEmailTemplates(OrgId);
		resetDisplayList();
	}
	
	public void refresh(){
		leTemplate= SelectContactController.getEmailTemplates(selectedFolderId);
		resetDisplayList();
	}
	
	private void resetDisplayList(){
		iseTemplateEmpty = leTemplate.isEmpty();
		iseTemplateNotEmpty = !leTemplate.isEmpty();
	}
}